/**
 *
 * User: zhikang.peng
 * Date: 2018/07/03 10:03
 */
package native

import (
	"gitee.com/thghh/jvmgo/rtda"
)

type NativeMethod func(frame *rtda.Frame)

var registry = map[string]NativeMethod{}

func emptyNativeMethod(frame *rtda.Frame) {
	// do nothing
}

// 注册本地方法
func Register(className string, methodName string, methodDescriptor string, method NativeMethod) {
	key := className + "~" + methodName + "~" + methodDescriptor
	registry[key] = method
}

// 寻找注册的本地方法
func FindNativeMethod(className string, methodName string, methodDescriptor string) NativeMethod {
	key := className + "~" + methodName + "~" + methodDescriptor
	if method, ok := registry[key]; ok {
		return method
	}

	if methodDescriptor == "()V" && methodName == "registerNatives" {
		return emptyNativeMethod
	}
	return nil
}
